package cn.gem.rainbow.api;

import cn.gem.rainbow.cfg.aop.CustomAnnotation;
import cn.gem.rainbow.pojo.entity.Book;
import cn.gem.rainbow.cfg.restful.APIException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BookController {

    @CustomAnnotation(name = "测试接口aop")
    @GetMapping("/getBook")
    @RequiresPermissions("login")
    public Book getBook(){
        Book book=new Book();
        book.setCode("12qwe112qq12");
        book.setDesc("测试");
        book.setId(1L);
        book.setName("java编程");
        return book;
    }

    @GetMapping("/getBook2")
    public Book getBook2(){
        Book book=new Book();
        book.setCode("12qwe112qq12");
        book.setDesc("测试");
        book.setId(1L);
        book.setName("java编程");
        throw new APIException();
    }

    /**
     * 访问rest风格的 500错误
     * http://localhost:8080/rainbow/getBook3
     * 会返回既定的Json  {"code":5000,"msg":"未知错误","data":"/ by zero","timestamp":1600533726973}
     * @return
     */
    @GetMapping("/getBook3")
    public Book getBook3(){
        Book book=new Book();
        int a =3/0;
        book.setCode("12qwe112qq12");
        book.setDesc("测试");
        book.setId((long) a);
        book.setName("java编程");
        return book;
    }


}
